
function patchClass(el, value) {
    if (value == null) {
        value = '';
    }
    el.className = value
}
function patchStyle(el,prev,next){ // {color:red}  {background:red}
    const style = el.style;
    if(!next){
        el.removeAttribute('style'); // 说明不需要有样式
    }else{
        for(let key in next){
            style[key] = next[key]
        }
        if(prev){
            for(let key in prev){
                if(next[key] == null){
                    style[key] = ''
                }
            }
        }
    }
}
function patchAttr(el,key,value){
    if(value == null){
        el.removeAttribute(key);
    }else{
        el.setAttribute(key,value);
    }
}
export function patchProp(el, key, prevValue, nextValue) {
    switch (key) {
        case 'class':
            patchClass(el, nextValue);
            break;
        case 'style':
            // {color:'red'}
            patchStyle(el,prevValue,nextValue);
            break;
        default:
            patchAttr(el,key,nextValue);
    }
}